package com.CRApp.controller;

import com.CRApp.pojo.Products;
import com.CRApp.pojo.ProductsClassify;
import com.CRApp.pojo.ProductsDetails;
import com.CRApp.pojo.ProductsDetailsDTO;
import com.CRApp.pojo.Result;
import com.CRApp.service.ProductsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: ProductsController
 * @Author : LuoFan洛樊
 * @Date : 2025/3/27 - 22:12
 * Description : 商品
 */
@RestController
@RequestMapping("/products")
@Validated
public class ProductsController {

    @Autowired
    private ProductsService productsService;

//    获取宠物商品类目
    @GetMapping("/catagory")
    public Result<List<Products>> Catagory() {
        List<Products> productsCatagory = productsService.getProductsCatagory();
        return Result.success(productsCatagory);
    }

    //根据商品类目查询商品种类
    @PostMapping("/Classify")
    public Result<List<ProductsClassify>> productsClassify(Integer catagoryId) {
        List<ProductsClassify> productsClassifyList = productsService.getProductsClassifyList(catagoryId);
        return Result.success(productsClassifyList);
    }

    //根据商品id查询商品详情列表
    @PostMapping("/detailsList")
    public Result<List<ProductsDetails>> detailsList(Integer catagoryId) {
        List<ProductsDetails> productsDetailsList = productsService.getProductsDetailsList(catagoryId);
        return Result.success(productsDetailsList);
    }

    //商品详细信息
    @PostMapping("/goodsDetails/{id}")
    public Result<ProductsDetailsDTO> details(@PathVariable("id") Integer id) {
        ProductsDetailsDTO productsDetails = productsService.getProductsDetails(id);
        return Result.success(productsDetails);
    }


}
